package com.rm.questions.service.impl;

import cn.hutool.core.convert.Convert;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.rm.questions.entity.CoreCategory;
import com.rm.questions.mapper.CoreCategoryMapper;
import com.rm.questions.service.ICoreCategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 题库分类Service业务层处理
 * 
 * @author sh
 * @date 2025-03-25
 */
@Service
public class CoreCategoryServiceImpl extends ServiceImpl<CoreCategoryMapper, CoreCategory> implements ICoreCategoryService
{
    @Autowired
    private CoreCategoryMapper coreCategoryMapper;

    /**
     * 查询题库分类
     * 
     * @param id 题库分类主键
     * @return 题库分类
     */
    @Override
    public CoreCategory selectById(Long id)
    {
        return coreCategoryMapper.selectById(id);
    }

    /**
     * 查询题库分类列表
     * 
     * @param coreCategory 题库分类
     * @return 题库分类
     */
    @Override
    public List<CoreCategory> selectList(CoreCategory coreCategory)
    {
        return coreCategoryMapper.selectList(coreCategory);
    }

    /**
     * 新增题库分类
     * 
     * @param coreCategory 题库分类
     * @return 结果
     */
    @Override
    public int insert(CoreCategory coreCategory)
    {
        return coreCategoryMapper.insert(coreCategory);
    }

    /**
     * 修改题库分类
     * 
     * @param coreCategory 题库分类
     * @return 结果
     */
    @Override
    public int update(CoreCategory coreCategory)
    {
        if(coreCategory.getFatherId()==null){
            coreCategory.setFatherId(0L);
        }
        return coreCategoryMapper.update(coreCategory);
    }

    /**
     * 批量删除题库分类
     * 
     * @param ids 需要删除的题库分类主键
     * @return 结果
     */
    @Override
    public int deleteByIds(String ids)
    {
        return coreCategoryMapper.deleteByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除题库分类信息
     * 
     * @param id 题库分类主键
     * @return 结果
     */
    @Override
    public int deleteById(Long id)
    {
        return coreCategoryMapper.deleteById(id);
    }

    /**
     * 根据父分类ID查询分类信息
     *
     * @param fatherId 父分类主键
     * @return 分类信息
     */
    @Override
    public List<CoreCategory> selectByFatherId(String fatherId){
        return coreCategoryMapper.selectByFatherId(fatherId);
    }


}
